home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / src / op-m-m.cc < prev    next >
C/C++ Source or Header  |  1997-01-24  |  6KB  |  237 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if defined (__GNUG__)
  24. #pragma implementation
  25. #endif
  26.  
  27. #ifdef HAVE_CONFIG_H
  28. #include <config.h>
  29. #endif
  30.  
  31. #include "gripes.h"
  32. #include "ov.h"
  33. #include "ov-re-mat.h"
  34. #include "ov-typeinfo.h"
  35. #include "op-m-m.h"
  36. #include "ops.h"
  37. #include "xdiv.h"
  38. #include "xpow.h"
  39.  
  40. // matrix by matrix ops.
  41.  
  42. static octave_value
  43. add (const octave_value& a1, const octave_value& a2)
  44. {
  45.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  46.  
  47.   return octave_value (v1.matrix_value () + v2.matrix_value ());
  48. }
  49.  
  50. static octave_value
  51. sub (const octave_value& a1, const octave_value& a2)
  52. {
  53.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  54.  
  55.   return octave_value (v1.matrix_value () - v2.matrix_value ());
  56. }
  57.  
  58. static octave_value
  59. mul (const octave_value& a1, const octave_value& a2)
  60. {
  61.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  62.  
  63.   return octave_value (v1.matrix_value () * v2.matrix_value ());
  64. }
  65.  
  66. static octave_value
  67. div (const octave_value& a1, const octave_value& a2)
  68. {
  69.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  70.  
  71.   return xdiv (v1.matrix_value (), v2.matrix_value ());
  72. }
  73.  
  74. static octave_value
  75. pow (const octave_value&, const octave_value&)
  76. {
  77.   error ("can't do A ^ B for A and B both matrices");
  78.   return octave_value ();
  79. }
  80.  
  81. static octave_value
  82. ldiv (const octave_value& a1, const octave_value& a2)
  83. {
  84.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  85.  
  86.   return xleftdiv (v1.matrix_value (), v2.matrix_value ());
  87. }
  88.  
  89. #define BOOL_OP(OP, ONE_EMPTY_RESULT, TWO_EMPTY_RESULT) \
  90.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (), \
  91.          Matrix, m2, v2.matrix_value (), \
  92.          m1 (i, j) OP m2 (i, j), #OP, \
  93.          ONE_EMPTY_RESULT, TWO_EMPTY_RESULT)
  94.  
  95. static octave_value
  96. lt (const octave_value& a1, const octave_value& a2)
  97. {
  98.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  99.  
  100.   BOOL_OP (<, Matrix (), Matrix ());
  101. }
  102.  
  103. static octave_value
  104. le (const octave_value& a1, const octave_value& a2)
  105. {
  106.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  107.  
  108.   BOOL_OP (<=, Matrix (), Matrix ());
  109. }
  110.  
  111. static octave_value
  112. eq (const octave_value& a1, const octave_value& a2)
  113. {
  114.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  115.  
  116.   BOOL_OP (==, 0.0, 1.0);
  117. }
  118.  
  119. static octave_value
  120. ge (const octave_value& a1, const octave_value& a2)
  121. {
  122.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  123.  
  124.   BOOL_OP (>=, Matrix (), Matrix ());
  125. }
  126.  
  127. static octave_value
  128. gt (const octave_value& a1, const octave_value& a2)
  129. {
  130.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  131.  
  132.   BOOL_OP (>, Matrix (), Matrix ());
  133. }
  134.  
  135. static octave_value
  136. ne (const octave_value& a1, const octave_value& a2)
  137. {
  138.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  139.  
  140.   BOOL_OP (!=, 1.0, 0.0);
  141. }
  142.  
  143. static octave_value
  144. el_mul (const octave_value& a1, const octave_value& a2)
  145. {
  146.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  147.  
  148.   return octave_value (product (v1.matrix_value (), v2.matrix_value ()));
  149. }
  150.  
  151. static octave_value
  152. el_div (const octave_value& a1, const octave_value& a2)
  153. {
  154.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  155.  
  156.   return octave_value (quotient (v1.matrix_value (), v2.matrix_value ()));
  157. }
  158.  
  159. static octave_value
  160. el_pow (const octave_value& a1, const octave_value& a2)
  161. {
  162.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  163.  
  164.   return elem_xpow (v1.matrix_value (), v2.matrix_value ());
  165. }
  166.  
  167. static octave_value
  168. el_ldiv (const octave_value& a1, const octave_value& a2)
  169. {
  170.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  171.  
  172.   return octave_value (quotient (v2.matrix_value (), v1.matrix_value ()));
  173. }
  174.  
  175. static octave_value
  176. el_and (const octave_value& a1, const octave_value& a2)
  177. {
  178.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  179.  
  180.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  181.          Matrix, m2, v2.matrix_value (),
  182.          m1 (i, j) && m2 (i, j), "&",
  183.          Matrix (), Matrix ());
  184. }
  185.  
  186. static octave_value
  187. el_or (const octave_value& a1, const octave_value& a2)
  188. {
  189.   CAST_BINOP_ARGS (const octave_matrix&, const octave_matrix&);
  190.  
  191.   MX_MX_BOOL_OP (Matrix, m1, v1.matrix_value (),
  192.          Matrix, m2, v2.matrix_value (),
  193.          m1 (i, j) || m2 (i, j), "|",
  194.          Matrix (), Matrix ());
  195. }
  196.  
  197. static octave_value
  198. assign (octave_value& a1, const octave_value_list& idx,
  199.     const octave_value& a2)
  200. {
  201.   CAST_BINOP_ARGS (octave_matrix&, const octave_matrix&);
  202.  
  203.   v1.assign (idx, v2.matrix_value ());
  204.   return octave_value ();
  205. }
  206.  
  207. void
  208. install_m_m_ops (void)
  209. {
  210.   INSTALL_BINOP (add, octave_matrix, octave_matrix, add);
  211.   INSTALL_BINOP (sub, octave_matrix, octave_matrix, sub);
  212.   INSTALL_BINOP (mul, octave_matrix, octave_matrix, mul);
  213.   INSTALL_BINOP (div, octave_matrix, octave_matrix, div);
  214.   INSTALL_BINOP (pow, octave_matrix, octave_matrix, pow);
  215.   INSTALL_BINOP (ldiv, octave_matrix, octave_matrix, ldiv);
  216.   INSTALL_BINOP (lt, octave_matrix, octave_matrix, lt);
  217.   INSTALL_BINOP (le, octave_matrix, octave_matrix, le);
  218.   INSTALL_BINOP (eq, octave_matrix, octave_matrix, eq);
  219.   INSTALL_BINOP (ge, octave_matrix, octave_matrix, ge);
  220.   INSTALL_BINOP (gt, octave_matrix, octave_matrix, gt);
  221.   INSTALL_BINOP (ne, octave_matrix, octave_matrix, ne);
  222.   INSTALL_BINOP (el_mul, octave_matrix, octave_matrix, el_mul);
  223.   INSTALL_BINOP (el_div, octave_matrix, octave_matrix, el_div);
  224.   INSTALL_BINOP (el_pow, octave_matrix, octave_matrix, el_pow);
  225.   INSTALL_BINOP (el_ldiv, octave_matrix, octave_matrix, el_ldiv);
  226.   INSTALL_BINOP (el_and, octave_matrix, octave_matrix, el_and);
  227.   INSTALL_BINOP (el_or, octave_matrix, octave_matrix, el_or);
  228.  
  229.   INSTALL_ASSIGNOP (octave_matrix, octave_matrix, assign);
  230. }
  231.  
  232. /*
  233. ;;; Local Variables: ***
  234. ;;; mode: C++ ***
  235. ;;; End: ***
  236. */
  237.